local M = require "packages/mamashengde/record/Made"

local henghui = fk.CreateSkill {
  name = "shine__henghui",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["shine__henghui"] = "恒辉",
  [":shine__henghui"] = "锁定技，当你变身后，你获得任意个效果并消耗等量的魔力：1.使用【杀】的次数和造成的伤害+1；"..
  "2.【杀】无距离限制且目标数+2；3.摸五张牌并弃置装备区内的所有牌。",

  ["henghui1"] = "使用【杀】的次数和伤害+1",
  ["henghui2"] = "【杀】无距离限制且目标数+2",
  ["@shine__henghui1"] = "次数和伤害+",
  ["@shine__henghui2"] = "无距且目标+",
  ["henghui3"] = "摸五张牌并弃置装备区所有牌",
  ["#henghui-choice"] = "恒辉：你可以选择任意项并消耗等量的魔力",
}

henghui:addEffect(M.HenshinEntered, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return data and data.who == player and player:hasSkill(henghui.name) and M.getMaryoku(player) > 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local choices = room:askToChoices(player, {
      choices = {"henghui1", "henghui2", "henghui3"},
      min_num = 1,
      max_num = M.getMaryoku(player),
      skill_name = henghui.name,
      prompt = "#henghui-choice",
      cancelable = true,
    })
    if #choices > 0 then
      event:setCostData(self, {choice = choices})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choices = event:getCostData(self).choice
    M.changeMaryoku(player, -#choices, henghui.name)
    if table.contains(choices, "henghui1") then
      room:addPlayerMark(player, "@shine__henghui1", 1)
    end
    if table.contains(choices, "henghui2") then
      room:addPlayerMark(player, "@shine__henghui2", 2)
    end
    if table.contains(choices, "henghui3") then
      player:drawCards(5, henghui.name)
      if not player.dead and #player:getCardIds("e") > 0 then
        player:throwAllCards("e", henghui.name)
      end
    end
  end,
})

henghui:addEffect(fk.AfterCardUseDeclared, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@shine__henghui1") > 0 and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    data.additionalDamage = (data.additionalDamage or 0) + player:getMark("@shine__henghui1")
  end,
})

henghui:addEffect("targetmod", {
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("@shine__henghui1") > 0 and scope == Player.HistoryPhase then
      return player:getMark("@shine__henghui1")
    end
  end,
  bypass_distances =  function(self, player, skill)
    return skill.trueName == "slash_skill" and player:getMark("@shine__henghui2") > 0
  end,
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:getMark("@shine__henghui2") > 0 then
      return player:getMark("@shine__henghui2")
    end
  end,
})

henghui:addLoseEffect(function (self, player)
  player.room:setPlayerMark(player, "@shine__henghui1", 0)
  player.room:setPlayerMark(player, "@shine__henghui2", 0)
end)

return henghui